/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package za.co.pas.spaceandtime.data;

import java.io.Serializable;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import za.co.pas.business.data.GenericData;

/**
 * Max capacity is only an indication. Actual max capacity is stored in room
 * @author alabuschagne
 */
@Entity
public class Bed extends GenericData implements Serializable
{

    private static final long serialVersionUID = 1L;
    
    private BedType bedType;
    private Integer maxCapacity;
    private Boolean enabled;
    

    @Override
    public int hashCode()
    {
        return super.hashCode();
    }

    @Override
    public boolean equals(Object object)
    {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Bed))
        {
            return false;
        }
        Bed other = (Bed) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id)))
        {
            return false;
        }
        return true;
    }

    @Override
    public String toString()
    {
        StringBuilder sb = new StringBuilder("Bed [");
        sb.append(id);
        sb.append("] ");
        if(bedType != null)
        {
            sb.append(bedType.getName());
        }
        return  sb.toString();
    }

    /**
     * @return the bedType
     */
    @ManyToOne(cascade=CascadeType.ALL)
    public BedType getBedType()
    {
        return bedType;
    }

    /**
     * @param bedType the bedType to set
     */
    public void setBedType(BedType bedType)
    {
        this.bedType = bedType;
    }

    public boolean check(Bed otherBed)
    {
        if((bedType == null) && (otherBed.getBedType() != null))
        {
            return false;
        }
        else if((bedType != null) && (!bedType.check(otherBed.getBedType())))
        {
            return false;
        }
        return true;
    }

    @Override
    public Bed clone()
    {
       Bed newBed = new Bed();
       newBed.setId(id);
       if(bedType != null)
       {
           newBed.setBedType(bedType.clone());
       }
       return newBed;
    }

    /**
     * @return the maxCapacity
     */
    public Integer getMaxCapacity()
    {
        return maxCapacity;
    }

    /**
     * @param maxCapacity the maxCapacity to set
     */
    public void setMaxCapacity(Integer maxCapacity)
    {
        this.maxCapacity = maxCapacity;
    }

    /**
     * @return the enabled
     */
    public Boolean getEnabled()
    {
        return enabled;
    }

    /**
     * @param enabled the enabled to set
     */
    public void setEnabled(Boolean enabled)
    {
        this.enabled = enabled;
    }
}
